﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
///Performance 的摘要说明
/// </summary>
public class Performance
{
    public Performance()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }
    /// <summary>
    /// 获取列表(分页)
    /// </summary>
    /// <param name="PageSize"></param>
    /// <param name="PageIndex"></param>
    /// <param name="Wheres"></param>
    /// <returns></returns>
    public static List<PerformanceInfo> GetList(int PageSize, int PageIndex, string Wheres)
    {
        DBCls db = new DBCls();
        SqlParameter[] parameters = { new SqlParameter("@PageSize",SqlDbType.Int,4),
                                            new SqlParameter("@PageIndex",SqlDbType.Int,4),
                                            new SqlParameter("@Wheres", SqlDbType.VarChar, 2000) };
        parameters[0].Value = PageSize;
        parameters[1].Value = PageIndex;
        parameters[2].Value = Wheres;
        using (SqlDataReader reader = db.ExecuteReader(CommandType.StoredProcedure, "Performance_GetList_SliptPage", parameters))
        {
            List<PerformanceInfo> list = new List<PerformanceInfo>();
            while (reader.Read())
            {
                PerformanceInfo info = new PerformanceInfo();
                info.PerformanceID = reader["PerformanceID"].ToString();
                info.KeyUnitName = reader["KeyUnitName"].ToString();
                info.PerformanceState = reader["PerformanceState"].ToString();
                info.UpTime = Convert.ToDateTime(reader["UpTime"].ToString());
                info.WriteTime = Convert.ToDateTime(reader["WriteTime"].ToString());

                list.Add(info);
            }
            return list;
        }
    }
    /// <summary>
    /// 获取列表的条数
    /// </summary>
    /// <param name="Where"></param>
    /// <returns></returns>
    public static int GetCount(string Where)
    {
        DBCls db = new DBCls();

        SqlParameter[] parameters = { new SqlParameter("@StrWhere", SqlDbType.VarChar, 4000) };
        parameters[0].Value = Where;
        SqlDataReader reader = db.ExecuteReader(CommandType.StoredProcedure, "Performance_GetCount", parameters);
        if (reader.Read())
        {
            return Convert.ToInt32(reader[0]);
        }
        else
        {
            return 0;
        }


    }
}
